package com.hope.onlinestudy.activity.integral

import android.support.v7.widget.LinearLayoutManager
import android.view.View
import com.hope.onlinestudy.R
import com.hope.onlinestudy.adapter.PointAdapter
import com.hope.onlinestudy.model.PointListModel
import com.hope.onlinestudy.model.PointModel
import com.hope.onlinestudy.mvp.MVPBaseActivity
import com.hope.onlinestudy.view.RecycleViewDivider
import com.jcodecraeer.xrecyclerview.XRecyclerView
import kotlinx.android.synthetic.main.activity_integral.*
import kotlinx.android.synthetic.main.view_title.*

/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */
class IntegralActivity :
    MVPBaseActivity<IntegralContract.View, IntegralPresenter>(), View.OnClickListener,
    XRecyclerView.LoadingListener,
    IntegralContract.View {

    private var page: Int = 1
    private val adapter: PointAdapter<PointModel> by lazy { PointAdapter<PointModel>() }

    override fun getLayoutView(): Int {
        return R.layout.activity_integral
    }

    override fun initData() {
        tv_title.text = "我的积分"
        iv_backup.setOnClickListener(this)

        rcvList.layoutManager = LinearLayoutManager(this)
        rcvList.addItemDecoration(RecycleViewDivider(this, LinearLayoutManager.VERTICAL))
        rcvList.adapter = adapter
        rcvList.setLoadingListener(this)
        rcvList.setPullRefreshEnabled(false)
        mPresenter?.getPoint()
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.iv_backup -> finish()
        }
    }

    override fun onLoadMore() {
        page++
        mPresenter?.getPoint(page)
    }

    override fun onRefresh() {
        page = 1
        mPresenter?.getPoint()
    }

    override fun reflashCommpand() {
        rcvList.refreshComplete()
        rcvList.loadMoreComplete()
    }

    override fun getPointData(data: PointListModel?, allData: ArrayList<PointModel>) {
        adapter.setDataEntityList(allData)
        tvStudent.text = "${data?.studyPoint}"
        tvPayNum.text = "${data?.shoopPoint}"
    }
}